package airacrobats.util;

import java.awt.Color;
import java.awt.Graphics;

/**
 * Useful methods.
 */
public class Util
{
    /**
     * Draws a string with outline effect.
     * @param string The string.
     * @param color The color.
     * @param outlineColor The outline color.
     * @param g The graphics.
     * @param x X position.
     * @param y Y position.
     */
    public static void drawOutlinedString(String string, Color color, Color outlineColor,
            Graphics g, int x, int y)
    {
        g.setColor(outlineColor);
        g.drawString(string, x - 1, y);
        g.drawString(string, x + 1, y);
        g.drawString(string, x, y - 1);
        g.drawString(string, x, y + 1);
        g.setColor(color);
        g.drawString(string, x, y);
    }

    /**
     * @param color Bar color.
     * @param lineColor Border color.
     * @param g Graphics.
     * @param x X position.
     * @param y Y position.
     * @param width Width.
     * @param height Height.
     * @param value The value of the bar (percentage 1 to 100).
     * @param borderSize Border size.
     */
    public static void drawVerticalBar(Color color, Color lineColor, Graphics g,
            int x, int y, int width, int height, int value, int borderSize)
    {
        g.setColor(lineColor);
        g.fillRect(x, y, width + borderSize * 2, height + borderSize * 2);
        g.setColor(color);
        g.fillRect(x + borderSize, y + borderSize, width, (int) (height * value / 100.0f));
    }
    
    /**
     * Draws a squared display.
     * @param color The color.
     * @param lineColor The lines color.
     * @param g The graphics.
     * @param x X position.
     * @param y Y position.
     * @param height The height of the display.
     * @param width The width of the display.
     * @param displacement The displacement between the lines.
     */
    public static void drawSquareDisplay(Color color, Color lineColor, Graphics g, int x, int y,
            int height, int width, int displacement)
    {
        g.setColor(Color.BLACK);
        g.fillRoundRect(x, y, width, height, 5, 5);
        g.setColor(Color.WHITE);
        g.drawRoundRect(x, y, width, height, 5, 5);
        int shortLine = 2;
        if (displacement > 0)
        {
            for (int i = displacement; i < height; i += displacement)
            {
                g.setColor(Color.WHITE);
                g.drawLine(x, y + i, x + width, y + i);
                g.setColor(Color.BLACK);
                g.drawLine(x + shortLine, y + i, x + width - shortLine, y + i);
                shortLine = (shortLine == 2) ? 4 : 2;
            }
        }
    }

    /**
     * Draws a round display.
     * @param color The color.
     * @param lineColor The lines color.
     * @param g The graphics.
     * @param x X position.
     * @param y Y position.
     * @param radius The display radius.
     * @param angle The angle between the lines.
     */
    public static void drawDisplay(Color color, Color lineColor, Graphics g, int x, int y, int radius, int angle)
    {
        g.setColor(Color.BLACK);
        g.fillArc(x, y, radius * 2, radius * 2, 0, 360);
        g.setColor(Color.WHITE);
        g.drawArc(x, y, radius * 2, radius * 2, 0, 360);
        int longLine = 2;
        for (int i = 0; i < 360; i += angle)
        {
            g.drawLine(x + radius + (int) (Math.cos(Math.toRadians(i)) * (radius - 7 + longLine)),
                    y + radius + (int) (Math.sin(Math.toRadians(i)) * (radius - 7 + longLine)),
                    x + radius + (int) (Math.cos(Math.toRadians(i)) * radius),
                    y + radius + (int) (Math.sin(Math.toRadians(i)) * radius));
            longLine = (longLine == 2) ? 0 : 2;
        }
    }
}
